using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace SimpleFactoryPattern
{
    public partial class Form1 : Form
    {
        bool bOperate = false;
        Operation oper;

        public Form1()
        {
            InitializeComponent();
        }

        private void InputNum(object sender, EventArgs e)
        {
            if (bOperate)
            {
                this.textBox1.Text = "";
                bOperate = false;
            }

            this.textBox1.Text = OperationFactory.checkNumberInput(this.textBox1.Text,((Button)sender).Text);
        }

        private void Equal(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(textBox1.Text))
            {
                string o = ((Button)sender).Text;
                if (o != "=")
                {
                    oper = OperationFactory.createOperation(o);
                }

                oper.NumberB = Convert.ToDouble(textBox1.Text);

                this.textBox1.Text = oper.GetResult().ToString();
                bOperate = true;
            }
        }

        private void Operater(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(textBox1.Text))
            {
                return;
            }
            oper = OperationFactory.createOperation(((Button)sender).Text);
            oper.NumberA = Convert.ToDouble(this.textBox1.Text);

            bOperate = true;
        }

        private void Clear(object sender, EventArgs e)
        {
            textBox1.Text = "";
        }
    }
}